package gameplate;

import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class GameFrame extends Frame {
    Image img = GameUtil.getImage("src/image/sun2.jpg");

    public void launchFrame() {
        setSize(800, 600);
        setLocation(100, 100);
        setVisible(true);
        new PaintThread().start();

        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }

    double x;
    double y;

    public void paint(Graphics gf) {
        gf.drawLine(100, 100, 200, 200);
        gf.drawOval(100, 100, 200, 300);
        gf.drawRect(100, 100, 200, 300);
        Font font = new Font("楷体", Font.BOLD, 100);
        gf.setFont(font);
        gf.drawString("heb作品:", 150, 150);

        Color c = gf.getColor();
        gf.setColor(Color.blue);
        gf.fillOval(100, 100, 20, 20);
        gf.setColor(c);

        gf.drawImage(img, (int) x, (int) y, null);
        x = x + 1;
        y = y + 1;
    }

    class PaintThread extends Thread {
        public void run() {
            while (true) {
                repaint();
                try {
                    Thread.sleep(40);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) {
        GameFrame gf = new GameFrame();
        gf.launchFrame();
    }
}
